<?php

class connectCallback_class 
{
	var $sina 	= 1;
	var $qq 	= 2;
	var $renren = 3;
	var $com 	= 'sanguo.com';
	
	
	/**
	 * Sina 登录 Call back 函数
	 * @param $p
	 */
	function sinaCallback($p) 
	{
		$token 	= vApi::param($p, 'oauth_token');
		$verify = vApi::param($p, 'oauth_verifier');
		if (empty($token) || empty($verify)) {
			vApi::throwException('417202', '获取Auth Token 失败');
		}
		
		// Get Auth Token From Cache
		$oCache 	= vApi::getBase('apiCache');
		$cachekey 	= $this->getAuthTokenCacheKey('sina', $token);
		$authToken 	= $oCache->get('authToken3rd', $cachekey);
		if (empty($authToken['oauth_token']) || empty($authToken['oauth_token_secret']) || is_null($authToken['_cbk'])) {
			vApi::throwException('417203', '获取Auth Token 缓存失败');
		}
		
		// Access Token
		$oWeibo 	= vApi::getClass('sinaapi/sinaWeibo');
		$accToken 	= $oWeibo->getAccessToken($authToken, $verify);
		if (empty($accToken)) {
			vApi::throwException('417204', '获取Access Token 失败');
		}
		
		// User Info
		$oWeibo->setToken($accToken['oauth_token'], $accToken['oauth_token_secret']);
		$bInfo = $oWeibo->getUserInfo();
		if (empty($bInfo['id'])) {
			vApi::throwException('417205', '获取第三方用户信息 失败');
		}
		
		// Db 操作
		$return				= array();
		$return['thd_uid']	= $bInfo['id'];
		$return['thd_nick']	= $bInfo['screen_name'];
		$return['thd_img']	= $this->_getProfileImg($bInfo, 'sina');
		$oBind = vApi::getBase('user_bind');
		$uInfo = $oBind->get3PartUser($this->sina, '', $bInfo['id']);
		
		// Add New User事务
		if (empty($uInfo['uid'])) 
		{
			$accData = array(
				'account' 		=> $this->_createAccount($bInfo['id'].'@sina.'.$this->com) ,
				'account_type' 	=> $this->sina,
				'create_time' 	=> APP_LOCAL_TIMESTAMP
			);
			$uid = vApi::getBase('account')->create($accData);
			if ( empty($uid) ) { return $return; }
			
			$thdPart = array(
				'uid'			=> $uid,
				'access_token' 	=> $accToken['oauth_token'],
				'token_secret' 	=> $accToken['oauth_token_secret'],
				'service_id' 	=> $this->sina,
				'connect_time' 	=> APP_LOCAL_TIMESTAMP,
				'thd_uid' 		=> $bInfo['id'],
				'thd_nick' 		=> $bInfo['screen_name']
			);
			$uid = $oBind->add3PartUser($thdPart);
			if ($uid) 
			{
				$return['uid'] 		= $uid;
//				$this->_addFriends($oWeibo, $uid, $bInfo['id'], 'sina');
			}
			return $return;
		}
		
		// Update Token
		$uid 	 		= $uInfo['uid'];
		$return['uid']	= $uid;
		$thdPart = array(
			'access_token' => $accToken['oauth_token'],
			'token_secret' => $accToken['oauth_token_secret'],
			'connect_time' => APP_LOCAL_TIMESTAMP
		);
		$oBind->update3PartToken($this->sina, $uid, $thdPart);
		return $return;
	}
	
	
	/**
	 * QQ 登录的Call back函数
	 * @param $p
	 */
	function qqCallback($p) 
	{
		$token 	= vApi::param($p, 'oauth_token');
		$verify = vApi::param($p, 'oauth_vericode');
		if (empty($token) || empty($verify)) {
			vApi::throwException('417202', '获取Auth Token 失败');
		}
		
		// Get Auth Token From Cache
		$oCache 	= vApi::getBase('apiCache');
		$cachekey 	= $this->getAuthTokenCacheKey('qq', $token);
		$authToken 	= $oCache->get('authToken3rd', $cachekey);
		if (empty($authToken['oauth_token']) || empty($authToken['oauth_token_secret']) || is_null($authToken['_cbk'])) {
			vApi::throwException('417203', '获取Auth Token 缓存失败');
		}
		
		// Access Token
		$oWeibo 	= vApi::getClass('qqapi/qqWeibo');
		$accToken 	= $oWeibo->getAccessToken($authToken, $verify);
		if (empty($accToken) || empty($accToken['openid'])) {
			vApi::throwException('417204', '获取Access Token 失败');
		}
		
		// User Info
		$bid   = $accToken['openid'];
		$oWeibo->setToken($accToken['oauth_token'], $accToken['oauth_token_secret']);
		$bInfo = $oWeibo->getUserInfo( array('openid'=>$bid) );

		
		// Db 操作
		$return				= array();
		$return['thd_uid']	= $bid;
		$return['thd_nick']	= $bInfo['nickname'];
		$return['thd_img']	= $this->_getProfileImg($bInfo, 'qq');
		
		$oBind 	= vApi::getBase('user_bind');
		$uInfo 	= $oBind->get3PartUser($this->qq, '', $bid);
		
		// Add New User
		if (empty($uInfo['uid'])) 
		{
			if (empty($bInfo['nickname'])) {
				vApi::throwException('417205', '获取第三方用户信息 失败');
			}
		
			$profile = $this->_getProfileImg($bInfo, 'qq');
			$accData = array(
				'account' 		=> $this->_createAccount($bid.'@qq.'.$this->com) ,
				'account_type' 	=> $this->qq,
				'create_time' 	=> APP_LOCAL_TIMESTAMP
			);
			$uid = vApi::getBase('account')->create($accData);
			if ( empty($uid) ) { return $return; }
			
			$thdPart = array(
				'uid'			=> $uid,
				'access_token' 	=> $accToken['oauth_token'],
				'token_secret' 	=> $accToken['oauth_token_secret'],
				'service_id' 	=> $this->qq,
				'connect_time' 	=> APP_LOCAL_TIMESTAMP,
				'thd_uid' 		=> $bid,
				'thd_nick' 		=> $bInfo['nickname']
			);
			$uid = $oBind->add3PartUser($thdPart);
			if ($uid) 
			{
				$return['uid']	= $uid;
//				$this->_addFriends($oWeibo, $uid, $bInfo['name'], 'qq');
			}
			return $return;
		}
		
		// Update Token
		$uid 	 		= $uInfo['uid'];
		$return['uid']	= $uid;
		$thdPart = array(
			'access_token' => $accToken['oauth_token'],
			'token_secret' => $accToken['oauth_token_secret'],
			'connect_time' => APP_LOCAL_TIMESTAMP
		);
		$oBind->update3PartToken($this->qq, $uid, $thdPart);
		return $return;
	}
	
	
	/**
	 * 人人 登录的Call back函数
	 * @param $p
	 */
	function renrenCallback($p) 
	{
		$code = vApi::param($p, 'code');
		if (empty($code)) {
			vApi::throwException('417202', '获取Auth code 失败');
		}
		
		// Access Token
		$_cbk 	= vApi::param($p, '_cbk');
		$_time 	= vApi::param($p, API_REQUEST_TIME_KEY);
		$req	= array('type'=>'renren', '_cbk'=>$_cbk, 'source'=>vApi::source(), '_ip'=>vApi::ip());
		
		$call_back 	= API_VYOUJI_API_URL . 'thd/connect_callback.smpauth?' . VF::signRequest($req, $_time);
		$oWeibo 	= vApi::getClass('renrenapi/renrenWeibo');
		$accToken 	= $oWeibo->getAccessToken($code, $call_back);
		if (empty($accToken['user'])) {
			vApi::throwException('417204', '获取Access Token 失败');
		}
		$bInfo  = $accToken['user'];
		
		
		// Db 操作
		$return	= array();
		$return['thd_uid']	= $bInfo['id'];
		$return['thd_nick']	= $bInfo['name'];
		$return['thd_img']	= $this->_getProfileImg($bInfo, 'renren');
				
		$oBind  = vApi::getBase('user_bind');
		$uInfo  = $oBind->get3PartUser($this->renren, '', $bInfo['id']);
		
		// Add New User
		if ( empty($uInfo['uid']) ) 
		{
			$accData 	= array(
				'account' 		=> $this->_createAccount($bInfo['id'].'@renren.'.$this->com) ,
				'account_type' 	=> $this->renren,
				'create_time' 	=> APP_LOCAL_TIMESTAMP
			);
			$uid = vApi::getBase('account')->create($accData);
			if ( empty($uid) ) { return $return; }
			
			$thdPart = array(
				'uid'				=> $uid,
				'access_token' 		=> $accToken['access_token'],
				'refresh_token' 	=> $accToken['refresh_token'],
				'service_id' 		=> $this->renren,
				'connect_time' 		=> APP_LOCAL_TIMESTAMP,
				'valid_time'		=> APP_LOCAL_TIMESTAMP + $accToken['expires_in'],
				'thd_uid' 			=> $bInfo['id'],
				'thd_nick' 			=> $bInfo['name']
			);
			
			$uid = $oBind->add3PartUser($thdPart);
			if ($uid) 
			{
				$return['uid']		= $uid;
//				$this->_addFriends($oWeibo, $uid, $bInfo['uid'], 'renren');
			}
			return $return;
		}
		
		// Update Token
		$uid 	 		= $uInfo['uid'];
		$return['uid']	= $uid;
		$thdPart = array(
			'access_token'  => $accToken['access_token'],
			'refresh_token' => $accToken['refresh_token'],
			'connect_time'  => APP_LOCAL_TIMESTAMP,
			'valid_time'	=> APP_LOCAL_TIMESTAMP + $accToken['expires_in']
		);
		$oBind->update3PartToken($this->renren, $uid, $thdPart);
		return $return;
	}
	
	
	/**
	 * 绑定Sina Call back 函数
	 * @param $p
	 */
	function bindSinaCallback($p) 
	{
		$token  = vApi::param($p, 'oauth_token');
		$verify = vApi::param($p, 'oauth_verifier');
		if (empty($token) || empty($verify)) {
			vApi::throwException('417402', '获取Auth Token 失败');
		}
		
		// Get Auth Token From Cache
		$oCache 	= vApi::getBase('apiCache');
		$cachekey 	= $this->getAuthTokenCacheKey('sina', $token);
		$authToken 	= $oCache->get('authToken3rd', $cachekey);
		if (empty($authToken['oauth_token']) || empty($authToken['oauth_token_secret']) || is_null($authToken['_cbk']) || empty($authToken['uid'])) {
			vApi::throwException('417403', '获取Auth Token 缓存失败');
		}
		
		
		// Access Token
		$oWeibo   = vApi::getClass('sinaapi/sinaWeibo');
		$accToken = $oWeibo->getAccessToken($authToken, $verify);
		if (empty($accToken)) {
			vApi::throwException('417404', '获取Access Token 失败');
		}
		
		
		// User Info
		$oWeibo->setToken($accToken['oauth_token'], $accToken['oauth_token_secret']);
		$bInfo = $oWeibo->getUserInfo();
		if (empty($bInfo['id'])) {
			vApi::throwException('417405', '获取第三方用户信息 失败');
		}
		
		// Check Data
		$uid    = $authToken['uid'];
		$oBind  = vApi::getBase('user_bind');
		$checkU = $oBind->get3PartUser($this->sina, '', $bInfo['id']);
		if (isset($checkU['uid']) && $checkU['uid']!=$uid) {
			vApi::throwException('417407', '第三方帐号已绑定');
		}
		
		
		// Add Or Update
		$return	 = array();
		$uInfo 	 = $oBind->get3PartUser($this->sina, $uid);
		$thdPart = array(
			'uid'			=> $uid,
			'access_token' 	=> $accToken['oauth_token'],
			'token_secret' 	=> $accToken['oauth_token_secret'],
			'service_id' 	=> $this->sina,
			'connect_time' 	=> APP_LOCAL_TIMESTAMP,
			'thd_uid' 		=> $bInfo['id'],
			'thd_nick' 		=> $bInfo['screen_name']
		);
		if (empty($uInfo['uid'])) 
		{
			$rst = $oBind->add3PartUser($thdPart);
			if ($rst) 
			{
				$return['uid'] 		= $uid;
				$return['thd_uid']	= $bInfo['id'];
//				$this->_addFriends($oWeibo, $uid, $bInfo['id'], 'sina');
			}
		} else { // 更新Token
			$return['uid'] = $uid;
			$rst = $oBind->update3PartToken($this->sina, $uid, $thdPart);
		}
		return $return;
	}
	
	
	/**
	 * 绑定QQ 的Call back函数
	 * @param $p
	 */
	function bindQQCallback($p) 
	{
		$token  = vApi::param($p, 'oauth_token');
		$verify = vApi::param($p, 'oauth_vericode');
		if (empty($token) || empty($verify)) {
			vApi::throwException('417402', '获取Auth Token 失败');
		}
		
		// Get Auth Token From Cache
		$oCache 	= vApi::getBase('apiCache');
		$cachekey 	= $this->getAuthTokenCacheKey('qq', $token);
		$authToken 	= $oCache->get('authToken3rd', $cachekey);
		if (empty($authToken['oauth_token']) || empty($authToken['oauth_token_secret']) || is_null($authToken['_cbk']) || empty($authToken['uid'])) {
			vApi::throwException('417403', '获取Auth Token 缓存失败');
		}
		
		// Access Token
		$oWeibo 	= vApi::getClass('qqapi/qqWeibo');
		$accToken 	= $oWeibo->getAccessToken($authToken, $verify);
		if (empty($accToken) || empty($accToken['openid'])) {
			vApi::throwException('417404', '获取Access Token 失败');
		}
		
		// Check Data
		$bid	= $accToken['openid'];
		$uid 	= $authToken['uid'];
		$oBind 	= vApi::getBase('user_bind');
		$checkU = $oBind->get3PartUser($this->qq, '', $bid);
		if (isset($checkU['uid']) && $checkU['uid']!=$uid) {
			vApi::throwException('417407', '第三方帐号已绑定');
		}
		
		// User Info
		$oWeibo->setToken($accToken['oauth_token'], $accToken['oauth_token_secret']);
		$bInfo = $oWeibo->getUserInfo( array('openid'=>$bid) );
		if (empty($bInfo['nickname'])) {
			vApi::throwException('417405', '获取第三方用户信息 失败');
		}
		
		
		// Add Binding Record
		$return	 = array();
		$uInfo 	 = $oBind->get3PartUser($this->qq, $uid);
		$thdPart = array(
			'uid'			=> $uid,
			'access_token' 	=> $accToken['oauth_token'],
			'token_secret' 	=> $accToken['oauth_token_secret'],
			'service_id' 	=> $this->qq,
			'connect_time' 	=> APP_LOCAL_TIMESTAMP,
			'thd_uid' 		=> $bid,
			'thd_nick' 		=> $bInfo['nickname']
		);
		if (empty($uInfo['uid'])) 
		{
			$rst = $oBind->add3PartUser($thdPart);
			if ($rst) 
			{
				$return['uid']		= $uid;
				$return['thd_uid']	= $bid;
				$return['thd_nick']	= $bInfo['nickname'];
				$return['thd_img']	= $this->_getProfileImg($bInfo, 'qq');
//				$this->_addFriends($oWeibo, $uid, $bInfo['name'], 'qq');
			}
		} else { // 更新Token
			$return['uid'] = $uid;
			$rst = $oBind->update3PartToken($this->qq, $uid, $thdPart);
		}
		return $return;
	}
	
	
	/**
	 * 绑定Renren 的Call back函数
	 * @param $p
	 */
	function bindRenrenCallback($p) 
	{
		$code = vApi::param($p, 'code');
		if (empty($code)) {
			vApi::throwException('417202', '获取Auth code 失败');
		}
		
		// Access Token
		$uid 	= vApi::param($p, 'b');
		$_cbk 	= vApi::param($p, '_cbk');
		$source = vApi::param($p, 'source');
		$_time 	= vApi::param($p, API_REQUEST_TIME_KEY);
		$req	= array('type'=>'renren', '_cbk'=>$_cbk, 'source'=>$source, 'b'=>$uid, '_ip'=>vApi::ip());
		
		$call_back 	= API_VYOUJI_API_URL . 'thd/bind_callback.smpauth?' . VF::signRequest($req, $_time);
		$oWeibo 	= vApi::getClass('renrenapi/renrenWeibo');
		$accToken 	= $oWeibo->getAccessToken($code, $call_back);
		if (empty($accToken['user']) || empty($uid)) {
			vApi::throwException('417204', '获取Access Token 失败');
		}
		
		
		// Db 操作
		$bInfo  = $accToken['user'];
		$oBind  = vApi::getBase('user_bind');
		$checkU = $oBind->get3PartUser($this->renren, '', $bInfo['id']);
		if (isset($checkU['uid']) && $checkU['uid']!=$uid) {
			vApi::throwException('417407', '第三方帐号已绑定');
		}
		
		// Add Binding Record
		$return	 = array();
		$uInfo 	 = $oBind->get3PartUser($this->renren, $uid);
		$thdPart = array(
			'uid'			=> $uid,
			'access_token' 	=> $accToken['access_token'],
			'refresh_token' => $accToken['refresh_token'],
			'service_id' 	=> $this->renren,
			'connect_time' 	=> APP_LOCAL_TIMESTAMP,
			'valid_time'	=> APP_LOCAL_TIMESTAMP + $accToken['expires_in'],
			'thd_uid' 		=> $bInfo['id'],
			'thd_nick' 		=> $bInfo['name']
		);
		if (empty($uInfo['uid'])) 
		{
			$rst = $oBind->add3PartUser($thdPart);
			if ($rst) 
			{
				$return['uid']		= $uid;
				$return['thd_uid']	= $bInfo['id'];
				$return['thd_nick']	= $bInfo['name'];
//				$this->_addFriends($oWeibo, $uid, $bInfo['name'], 'renren');
			}
		} else { // 更新Token
			$return['uid'] = $uid;
			$rst = $oBind->update3PartToken($this->renren, $uid, $thdPart);
		}
		return $return;
	}
	
	
	// 获取返回地址
	function getCallBackUrl($p, $type) 
	{
		$token = vApi::param($p, 'oauth_token');
		if ($token) 
		{
			$oCache 	= vApi::getBase('apiCache');
			$cachekey 	= $this->getAuthTokenCacheKey($type, $token);
			$authToken 	= $oCache->get('authToken3rd', $cachekey);
			if (isset($authToken['_cbk'])) { return $authToken['_cbk']; }
		}
		return '';
	}
	
	// 好友挖掘
	private function _addFriends($oWeibo, $uid, $bid, $type='sina') 
	{
		try 
		{
			// 获取第三方 FriendIds
			$rstIds = $this->_get3PartIds($oWeibo, $bid, $type);
			if (empty($rstIds)) {
				return TRUE;
			}
			
			// 转化成本地IDs
			$oBind 	 = vApi::getBase('user_bind');
			$uidList = $oBind->getUserIdsBy3partIds($rstIds, $this->$type);
			if (empty($uidList)) {
				return TRUE;
			}
			
			// 加关注
			$friUser 	= array();
			$oFsp 		= vApi::getBase('fsp');
			$oMsg 		= vApi::getBase('message');
			$userList 	= $oBind->getUsers($uidList);
			$friship 	= array();
			
			//添加关注关系
			foreach ($uidList as $fuid) 
			{
				// 用户 和关系检查
				if (empty($userList["$fuid"])) {
					continue;
				}
				$friship = $oFsp->getFriendShips($uid, $fuid);
				if ($friship['following']) {
					continue;
				}
				
				if ($oFsp->create($fuid, $uid)) {
					$oBind->updateCounter($fuid, array(
						'fl' => '+1'
					)); // 粉丝加1
					$oFsp->updateFriendShipCache($uid, $fuid, 'add'); // 更新缓存 - 关注关系列表
					$user = $userList["$fuid"];
					$friUser[] = array(
						'id' => $user['id'],
						'nickname' => $user['nickname']
					);
					if (count($friUser) >= API_FOLLOWER_SIZE_MAX) {
						break;
					}
				}
			}
			// 用户关注更改 和 发送消息
			if (count($friUser) > 0) {
				$oBind->updateCounter($uid, array(
					'fr' => '+' . count($friUser)
				)); // 加关注数
				$oFsp->cacheCall('getIdsByFollowed_db', array(
					$uid
				) , array(
					'kname' => 'fr',
					'kvar' => $uid
				) , TRUE);
				$oMsg->send($uid, 'hywj', array(
					'users' => $friUser
				));
				// 好友历史游记
				$data = array();
				$yjList = vApi::getBase('youji')->getYoujiIdsFromFrends($uid, 1);
				$yjList = array_slice($yjList, 0, 10);
				if (is_array($yjList)) {
					foreach ($yjList as $yjs) {
						if (is_array($yjs)) {
							foreach ($yjs as $aYj) {
								$data['users'][] = array(
									'id' => $aYj['user']['id'],
									'nickname' => $aYj['user']['nickname']
								);
								$data['youjis'][] = array(
									'id' => $aYj['id'],
									'title' => $aYj['title'],
									'uid' => $aYj['user']['id'],
									'unickname' => $aYj['user']['nickname']
								);
							}
						}
					}
				}
				if (!empty($data['users'])) {
					$oMsg->send($uid, 'yjls', $data);
				}
			}
			return TRUE;
		}
		catch(Exception $e) 
		{
			if (API_IS_DEBUG) { throw $e;}	// Debug模式下抛出异常
		} 
	}
	
	
	// 获取第三方用户ID
	private function _get3PartIds($oWeibo, $bid, $type) 
	{
		$rstIds = array();
		switch ($type) 
		{
//			case 'qq':
//				$rst = $oWeibo->getFriendIds();
//				if (!empty($rst['data']['info'])) {
//					foreach ($rst['data']['info'] as $aRow) {
//						$rstIds[] = $aRow['name'];
//					}
//				}
//			break;

//			// 人人
//			case 'renren':
//				$rst = $oWeibo->getAppFriends();
//				if (empty($rst['error_code'])) {
//					$rstIds = $rst;
//				}
//			break;

			// 新浪
			case 'sina':
			default:
				$rst = $oWeibo->getFriendsIds(array('uid'=>$bid, 'count'=>5000));
				if ( isset($rst['ids']) ) { $rstIds=$rst['ids']; }
		}
		return $rstIds;
	}
	
	
	/**
	 * 获取唯一昵称
	 * @param $nickname
	 */
	private function _createNickname($nickname, $type) 
	{
		if ($nickname) {
			$oBind = vApi::getBase('user');
			$oTookit = vApi::getBase('tookit');
			$kwords = $oTookit->chkKeyword($nickname, 2);
			if (empty($kwords)) {
				if (!$oBind->getUidByNick($nickname)) {
					return $nickname;
				}
				$nickname = $nickname . '_' . $type;
				if (!$oBind->getUidByNick($nickname)) {
					return $nickname;
				}
			}
			else {
				$zimu = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
				$zmMax = strlen($zimu) - 1;
				$nickname = $type . '用户' . substr($zimu, rand(0, $zmMax) , 1) . substr($zimu, rand(0, $zmMax) , 1);
				if (!$oBind->getUidByNick($nickname)) {
					return $nickname;
				}
			}
			//确保唯一性
			while (TRUE) {
				$nickname = $nickname . '_' . rand(0, 9) . rand(0, 9);
				if (!$oBind->getUidByNick($nickname)) {
					return $nickname;
				}
			}
		}
		vApi::throwException('417205', '获取第三方用户信息 失败');
	}
	
	
	/**
	 * 获取唯一Account
	 * @param $account
	 */
	private function _createAccount($account) 
	{
		if ($account) 
		{
			$oAccount 	= vApi::getBase('account');
			$emUid 		= $oAccount->getUidByEmail($account);
			if (empty($emUid)) { return $account; }
			
			$zimu 	 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
			$zmMax   = strlen($zimu) - 1;
			$com 	 = substr($zimu, rand(0, $zmMax) , 1) . substr($zimu, rand(0, $zmMax) , 1) . $this->com;
			$account = str_replace($this->com, $com, $account);
			$emUid 	 = $oAccount->getUidByEmail($account);
			if ( empty($emUid) ) { return $account; }
			
			//确保唯一性
			while (TRUE) 
			{
				$com 		= rand(0, 9) . $com;
				$account 	= str_replace($this->com, $com, $account);
				$rst 		= $oAccount->getUidByEmail($account);
				if (empty($rst)) { return $account; }
			}
		}
		vApi::throwException('417205', '获取第三方用户信息 失败');
	}
	
	
	/**
	 * 获取用户头像
	 * @param array $uInfo, 用户第三方信息
	 * @param string $type, sina/qq/renren
	 */
	private function _getProfileImg($uInfo, $type)
	{
		$profile = '';
		switch ($type) {
			case 'sina':
				if (!empty($uInfo['profile_image_url'])) {
					$urls = explode('/', $uInfo['profile_image_url']);
					$urls[4] = 180;
					$profile = implode('/', $urls);
				}
			break;
			case 'qq':
				if (!empty($uInfo['figureurl_2'])) {
					$profile = $uInfo['figureurl_2'];
				}
			break;
			case 'renren':
				if (!empty($uInfo['avatar'][0]['url'])) {
					$profile = $uInfo['avatar'][0]['url'];
				}
			break;
		}
		return $profile;
	}
	
	
	// 获取Token 的Cache key
	function getAuthTokenCacheKey($type, $authToken) {
		return TOKEN_PASS_KEY."#$type#$authToken";
	}
}
?>